package WORKPLACE;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import TOOLS.SQLtool;

public class test1 {

	public static void main(String[] args) throws Exception {
		SQLtool sql=new SQLtool();
		String IPaddr="192.168.1.1";
		try {
			InetAddress addr = InetAddress.getLocalHost();
			IPaddr=addr.getHostAddress();
		} catch (UnknownHostException e1) {
			;
		}
		sql.config(IPaddr, "AKS2019", "sa", "123456","test010");
		sql.config("192.168.0.39", "AKS2019", "sa", "abcd1234!","test009");
		int i=0;
		String itime=GetTimestamp("yyyyMM",i);
		while(!itime.equals("202005")) {
			i=i-1;
			itime=GetTimestamp("yyyyMM",i);
			String str="ALTER TABLE [SNhistory].[history_resultData_"+itime+"]  \r\n" + 
					"ADD lineID VARCHAR(100) NULL;";
			sql.Command(str);
		}
		
	}

	public static String GetTimestamp(String iformat,int shiftMonth) {
		// "2017-12-10 15:52:10";
		String timestamp = new String();
		SimpleDateFormat t = new SimpleDateFormat(iformat);
		Date idate=new Date();
		Calendar cal=Calendar.getInstance();
		cal.setTime(idate);
		cal.add(Calendar.MONTH, shiftMonth);
		idate=cal.getTime();
		timestamp = "" + t.format(idate);
		return timestamp;
	}
}
